//
//  IGCommunityBaseVC.m
//  jingdongfang
//
//  Created by BOE on 2017/8/21.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGCommunityBaseVC.h"
#import "IGTopicCommentTableViewCell.h"
#import "IGCommunityListVC.h"
#import "YXScrollowActionSheet.h"

//键盘
#import "ChatKeyBoard.h"
#import "FaceSourceManager.h"
#import "MoreItem.h"
#import "ChatToolBarItem.h"
#import "FaceThemeModel.h"
#import "IGCommonApi.h"
#import "IGReportTypeApi.h"
#import "IGReportVC.h"
#import "IGCommentApi.h"
#import "IGNetReachable.h"
#import "IGEmptyView.h"
#import "IGArtGalleryAttentApi.h"

@interface IGCommunityBaseVC ()<ChatKeyBoardDelegate, ChatKeyBoardDataSource, UITableViewDelegate, UITableViewDataSource, IGTopicTableViewCellDelegate, UIScrollViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>

@property (nonatomic, strong) ChatKeyBoard *chatKeyBoard;
///>记录table的offset.y
@property (nonatomic, assign) CGFloat history_Y_offset;
///>记录点击cell的高度，高度由代理传过来
@property (nonatomic, assign) CGFloat seletedCellHeight;
///>专门用来回复选中的cell的model
@property (nonatomic, strong) IGCommentBean *replayTheSeletedCellModel;
///>控制是否刷新table的offset
@property (nonatomic, assign) BOOL needUpdateOffset;
@property (nonatomic,copy) NSIndexPath *currentIndexPath;
@property (nonatomic, strong) IGReportTypeApi *reportTypeApi;
@property (nonatomic, strong) NSArray *reportTypeArr;
@property (nonatomic, strong) IGCommentApi *commentApi;

@end

@implementation IGCommunityBaseVC

#pragma mark -生命周期
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.heightForFirstSectionCell = 0.1f;
        self.heightForSecondSectionCell = 0.1f;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor mainBackgroundColor];

    // Do any additional setup after loading the view.
    AdjustsScrollViewInsetNever(self, self.tableView);
    //注册键盘出现NSNotification
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification object:nil];
    
    //注册键盘隐藏NSNotification
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification object:nil];
    
    //点赞-评论数据同步、发布话题刷新显示
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(topicListRefresh:)
                                                 name:@"kTopicListRefresh" object:nil];
    
    self.view.backgroundColor = [UIColor mainBackgroundColor];
    self.reportTypeApi = [[IGReportTypeApi alloc] init];
    self.commentApi = [[IGCommentApi alloc] init];
    
    [self.tableView registerClass:[IGTopicTableViewCell class] forCellReuseIdentifier:kIGTopicTableViewCell];
    [self.view addSubview:self.tableView];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(NavigationMagin);
    }];
    
}


- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    NSLogDebug(@"%@ dealloc", NSStringFromClass([self class]));
}

- (NSArray *)reportTypeArr {
    if (!_reportTypeArr) {
        _reportTypeArr = [NSArray array];
    }
    return _reportTypeArr;
}

#pragma -Request
- (void)likeTopic:(IGTopicModel *)model request:(NoParaNoReturnBlock)block {
    IGCommonApi *api = [[IGCommonApi alloc] initWithApiType:IGiGalleryApiTypeCircleTopicLike];
    api.topicId = model.tid;
    [api startWithDecodeClass:[IGCommonResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            if (block) {
                block();
            }
        }
    }];
}

- (void)reportRequest:(IGTopicModel *)model {
    
    __weak typeof(self) weakSelf = self;
    [self.reportTypeApi startWithDecodeClass:[IGReportTypeResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            IGReportTypeResp *resp = responseObject;
            IGReportTypeModel *type = resp.data;
            weakSelf.reportTypeArr = type.reports;
            
            IGReportVC *reportVC = [[IGReportVC alloc] initWithReportType:weakSelf.reportTypeArr];
            reportVC.pId = model.tid;
            [UIViewController ig_pushViewController:reportVC animated:YES];
        }
    }];
}

- (void)delTopicRequest:(IGTopicModel *)model indexPath:(NSIndexPath *)indexPath{
    
    IGCommonApi *api = [[IGCommonApi alloc] initWithApiType:IGiGalleryApiTypeCircleTopicDel];
    api.topicId = model.tid;
    __weak typeof(self) weakSelf = self;
    [api startWithDecodeClass:[IGCommonResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"kTopicListRefresh" object:NSStringFromClass([weakSelf class])];
            [weakSelf presentMessageTips:NSLocalizedString(@"Deleted Successfully", nil)];
        } else { //删除失败恢复数据源中的数据
            [weakSelf presentMessageTips:NSLocalizedString(@"Delete Failed", nil)];
            [weakSelf.dataSource insertObject:model atIndex:indexPath.row];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.tableView reloadData];
        });
    }];
}

- (void)commitCommentRequest {
    __weak typeof(self) weakSelf = self;
    [self.commentApi startWithDecodeClass:[IGCommentResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        IGTopicModel *topicModel = [weakSelf.dataSource objectAtIndex:weakSelf.currentIndexPath.row];
        if (responseObject) {
            IGCommentResp *resp = responseObject;
            IGCommentModel *model = resp.data;
            IGCommentBean *commentModel = model.comment;
            
            topicModel.commentNums = [NSString stringWithFormat:@"%d", ([topicModel.commentNums intValue] + 1)];
            [topicModel.lstComments replaceObjectAtIndex:0 withObject:commentModel];
        } else {
            [topicModel.lstComments removeObjectAtIndex:0];
            topicModel.commentNums = [NSString stringWithFormat:@"%d", ([topicModel.commentNums intValue] - 1)];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.tableView reloadData];
        });
    }];
}

#pragma mark -懒加载
- (NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.emptyDataSetSource = self;
        _tableView.emptyDataSetDelegate = self;
        
        if (@available(iOS 11.0, *)) {
            _tableView.estimatedRowHeight = 0;
            _tableView.estimatedSectionHeaderHeight = 0;
            _tableView.estimatedSectionFooterHeight = 0;
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor mainBackgroundColor];
    }
    return _tableView;
}

#pragma mark - 子类中实现
static NSString *const kCustomFirstSectionCellID = @"kCustomFirstSectionCellID";
- (UITableViewCell *)customFirstSectionCell:(UITableView *)tableView {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomFirstSectionCellID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomFirstSectionCellID];
    }
    return cell;
}

static NSString *const kCustomSecondSectionCellID = @"kCustomSecondSectionCellID";
- (UITableViewCell *)customSecondSectionCell:(UITableView *)tableView {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustomSecondSectionCellID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomSecondSectionCellID];
    }
    return cell;
}

- (void)attention:(IGTopicModel *)model {
    if ([model.userId isEqualToString:[IGUser getUid]]) {
        [self presentMessageTips:@"你不能关注你自己!"];
        [self.tableView reloadData];
        return;
    }
    __weak typeof(self) weakSelf = self;
    IGArtGalleryAttentApi *attentApi = [IGArtGalleryAttentApi new];
    attentApi.museumId = model.userId;
    attentApi.operatorType = [model.isCollection boolValue]?@"1":@"0";
    [attentApi startWithDecodeClass:[IGArtGalleryAttentResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
            if ([model.isCollection boolValue]) {
                model.isCollection = @"0";
            } else {
                model.isCollection = @"1";
            }
        } else {
            if ([model.isCollection boolValue]) {
                [self presentMessageTips:NSLocalizedString(@"Follow Failed", nil)];
            } else {
                [self presentMessageTips:NSLocalizedString(@"Cancel Failed", nil)];
            }
        }
        [weakSelf.tableView reloadData];
    }];
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0 || section == 1) {
        return 1;
    } else {
        return self.dataSource.count;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count>0?3:0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = nil;
    if (indexPath.section == 0) {
        return [self customFirstSectionCell:tableView];
    } else if (indexPath.section == 1) {
        return [self customSecondSectionCell:tableView];
    } else {
        IGTopicTableViewCell *cell = [IGTopicTableViewCell cellWithTableView:tableView];
        cell.delegate = self;
        
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        __weak __typeof(self) weakSelf = self;
        __weak __typeof(window) weakWindow = window;
        __weak __typeof(tableView) weakTableView = tableView;
        
        __block IGTopicModel *model = [self.dataSource objectAtIndex:indexPath.row];
        [cell configCellWithModel:model indexPath:indexPath];
        
        cell.focusUser = ^{
            [self attention:model];
        };
        
        //评论
        cell.commentBtnClickBlock = ^(UIButton *commentBtn,NSIndexPath * indexPath) {
            
            if (weakSelf.isShowKeyBoard) {
                [weakSelf.view endEditing:YES];
                return ;
            }
            
            //不是点击cell进行回复，则置空replayTheSeletedCellModel，因为这个时候是点击评论按钮进行评论，不是回复某某某
            weakSelf.replayTheSeletedCellModel = nil;
            weakSelf.seletedCellHeight = 0.0;
            weakSelf.needUpdateOffset = YES;
            weakSelf.chatKeyBoard.placeHolder = [NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"comment", nil),model.userNick];
            weakSelf.history_Y_offset = [commentBtn convertRect:commentBtn.bounds toView:weakWindow].origin.y;
            weakSelf.currentIndexPath = indexPath;
            [weakSelf.chatKeyBoard keyboardUpforComment];
        };
        
        cell.likeBlock = ^{
            
            [weakSelf likeTopic:model request:^() {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"kTopicListRefresh" object:NSStringFromClass([weakSelf class])];
                if (model.isZan) {
                    model.zanNums = [NSString stringWithFormat:@"%d", ([model.zanNums intValue] - 1)];
                } else {
                    model.zanNums = [NSString stringWithFormat:@"%d", ([model.zanNums intValue] + 1)];
                }
                model.isZan = !model.isZan;
                dispatch_async(dispatch_get_main_queue(), ^{
                    [weakSelf.tableView reloadData];
                });
            }];
        };
        
        cell.shareBlock = ^{
            if (weakSelf.isShowKeyBoard) {
                [weakSelf.view endEditing:YES];
                return ;
            }
            
            YXScrollowActionSheet *cusSheet = [[YXScrollowActionSheet alloc] init];
            NoParaNoReturnBlock reportBlock = ^() {
                [weakSelf reportRequest:model];
            };
            NoParaNoReturnBlock delBlock = ^() {
                
                [UIAlertView bk_showAlertViewWithTitle:NSLocalizedString(@"Notice", nil) message:NSLocalizedString(@"Confirm to delete this topic?",nil) cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:@[NSLocalizedString(@"Confirm", nil)] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                    if (buttonIndex == 1) {
                        // 从数据源中删除
                        [weakSelf.dataSource removeObjectAtIndex:indexPath.row];
                        // 从列表中删除
                        [weakTableView reloadData];
                        [weakSelf delTopicRequest:model indexPath:indexPath];
                    }
                }];
                
            };
            
            NSArray *contentArray = nil;
            NSArray *blockArray = nil;
            if ([[IGUser getUid] isEqualToString:model.userId]) {
                contentArray = @[NSLocalizedString(@"Report", nil), NSLocalizedString(@"Delete", nil)];
                blockArray = @[reportBlock, delBlock];
            } else {
                contentArray = @[NSLocalizedString(@"Report", nil)];
                blockArray = @[reportBlock];
            }
            
            IGShareModel *shareModel = [model getShareModel];
            cusSheet.shareModel = shareModel;
            [cusSheet showWithContentArray:contentArray blockArr:blockArray];
        };
        
        //点击九宫格
        cell.tapImageBlock = ^(NSInteger index,NSArray *dataSource,NSIndexPath *indexpath){
            if (weakSelf.isShowKeyBoard) {
                [weakSelf.view endEditing:YES];
                return ;
            }
            [weakSelf.chatKeyBoard keyboardDownForComment];
        };
        
        return cell;
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return self.heightForFirstSectionCell;
    } else if (indexPath.section == 1) {
        return self.heightForSecondSectionCell;
    } else {
        IGTopicModel *messageModel = [self.dataSource objectAtIndex:indexPath.row];
        CGFloat h = [IGTopicTableViewCell hyb_heightForTableView:tableView config:^(UITableViewCell *sourceCell) {
            IGTopicTableViewCell *cell = (IGTopicTableViewCell *)sourceCell;
            [cell configCellWithModel:messageModel indexPath:indexPath];
        } cache:^NSDictionary *{
            NSDictionary *cache = @{kHYBCacheUniqueKey : messageModel.tid,
                                    kHYBCacheStateKey  : @"",
                                    kHYBRecalculateForStateKey : @(messageModel.shouldUpdateCache)};
            messageModel.shouldUpdateCache = NO;
            return cache;
        }];
        return h + 20;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (self.isShowKeyBoard) {
        [self.view endEditing:YES];
        return;
    }
}

- (ChatKeyBoard *)chatKeyBoard {
    if (_chatKeyBoard == nil) {
        _chatKeyBoard = [ChatKeyBoard keyBoardWithNavgationBarTranslucent:YES];
        _chatKeyBoard.delegate = self;
        _chatKeyBoard.dataSource = self;
        _chatKeyBoard.keyBoardStyle = KeyBoardStyleComment;
        _chatKeyBoard.allowVoice = NO;
        _chatKeyBoard.allowMore = NO;
        _chatKeyBoard.allowFace = NO;
        _chatKeyBoard.allowSwitchBar = NO;
        _chatKeyBoard.placeHolder = NSLocalizedString(@"comment", nil);
        [self.view addSubview:_chatKeyBoard];
        [self.view bringSubviewToFront:_chatKeyBoard];
    }
    return _chatKeyBoard;
}

#pragma mark - passCellHeightWithModel
-(void)passCellHeight:(CGFloat)cellHeight commentModel:(IGCommentBean *)commentModel commentCell:(UITableViewCell *)commentCell messageCell:(IGTopicTableViewCell *)messageCell {
    if (self.isShowKeyBoard) {
        [self.view endEditing:YES];
        return ;
    }
    self.needUpdateOffset = YES;
    self.replayTheSeletedCellModel = commentModel;
    self.currentIndexPath = [self.tableView indexPathForCell:messageCell];
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.chatKeyBoard.placeHolder = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"Reply", nil),commentModel.commentUserNick];
    self.history_Y_offset = [commentCell convertRect:commentCell.bounds toView:window].origin.y;
    self.seletedCellHeight = cellHeight;
    [self.chatKeyBoard keyboardUpforComment];
}

- (void)reloadCellHeightForModel:(IGTopicModel *)model atIndexPath:(NSIndexPath *)indexPath {
    model.shouldUpdateCache = YES;
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

#pragma mark - keyboardWillShow
- (void)keyboardWillShow:(NSNotification *)notification
{
    UIApplication *application = [UIApplication sharedApplication];
    UIApplicationState applicationState = application.applicationState;
    if (applicationState != UIApplicationStateActive) {
        return;
    }
    
    self.isShowKeyBoard = YES;
    NSDictionary *userInfo = [notification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    __block CGFloat keyboardHeight = [aValue CGRectValue].size.height;
    if (keyboardHeight == 0) {
        //解决搜狗输入法三次调用此方法的bug、
        return;
    }
    CGRect keyboardRect = [aValue CGRectValue];
    keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
    CGFloat keyboardTop = keyboardRect.origin.y;
    CGRect newTextViewFrame = self.view.bounds;
    newTextViewFrame.size.height = keyboardTop - self.view.bounds.origin.y;
    
    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration;
    [animationDurationValue getValue:&animationDuration];
    CGFloat delta = 0.0;
    if (self.seletedCellHeight){//点击某行，进行回复某人
        delta = self.history_Y_offset - (KSCREENHEIGHT - keyboardHeight- self.seletedCellHeight - kChatToolBarHeight);
    } else {//点击评论按钮
        delta = self.history_Y_offset - (KSCREENHEIGHT - keyboardHeight- kChatToolBarHeight - 24 - 10);//24为评论按钮高度，10为评论按钮上部的5加评论按钮下部的5
    }
    CGPoint offset = self.tableView.contentOffset;
    offset.y += delta;
    if (offset.y < 0) {
        offset.y = 0;
    }
    if (self.needUpdateOffset) {
        [self.tableView setContentOffset:offset animated:YES];
    }
}

#pragma mark - keyboardWillHide
- (void)keyboardWillHide:(NSNotification *)notification {
    UIApplication *application = [UIApplication sharedApplication];
    UIApplicationState applicationState = application.applicationState;
    if (applicationState != UIApplicationStateActive) {
        return;
    }
    
    self.isShowKeyBoard = NO;
    self.needUpdateOffset = NO;
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    [self.view endEditing:YES];
}

# pragma mark - ChatKeyBoardDelegate
- (void)chatKeyBoardSendText:(NSString *)text{
    if ([text isEmpty]) {
        [self presentMessageTips:NSLocalizedString(@"Add your comments", nil)];

        return;
    }
    if (text.length > 300) {
        [self presentMessageTips:NSLocalizedString(@"Exceeding max word count. Input Not Available", nil)];
        
        return;
    }

    IGTopicModel *topicModel = [self.dataSource objectAtIndex:self.currentIndexPath.row];
    topicModel.shouldUpdateCache = YES;
    
    IGCommentType commentType = IGCommentTypeFirst;
    if (self.replayTheSeletedCellModel) {
        commentType = IGCommentTypeSecond;
    }
    
    //创建一个新的CommentModel,并给相应的属性赋值，然后加到评论数组的最后，reloadData
    IGCommentBean *commentModel = [[IGCommentBean alloc]init];
    commentModel.commentUserNick = [IGUser getNike];
    commentModel.commentUserId = [IGUser getUid];
    commentModel.commentUserAvater = [IGUser getImage];
    commentModel.parentCommentUserNick = (commentType == IGCommentTypeSecond)?self.replayTheSeletedCellModel.commentUserNick:@"";
    commentModel.parentCommentUserId = (commentType == IGCommentTypeSecond)?self.replayTheSeletedCellModel.commentUserId:@"";
    commentModel.commentId = @"000000";//临时ID
    commentModel.content = text;
    commentModel.shouldUpdateCache = YES;
    [topicModel.lstComments insertObject:commentModel atIndex:0];
    
    topicModel.shouldUpdateCache = YES;
    [self reloadCellHeightForModel:topicModel atIndexPath:self.currentIndexPath];
    [self.chatKeyBoard keyboardDownForComment];
    self.chatKeyBoard.placeHolder = nil;
    
    //提交数据==>若失败刷新界面
    self.commentApi.pid = topicModel.tid;
    self.commentApi.parentType = IGParentTypeTopic;
    self.commentApi.content = text;
    self.commentApi.commentType = commentType;
    self.commentApi.opusId = topicModel.product.artId;
    if (commentType == IGCommentTypeFirst) {
        self.commentApi.parentUid = topicModel.userId;
        self.commentApi.cId = @"";
    } else {
        self.commentApi.parentUid = self.replayTheSeletedCellModel.commentUserId;
        self.commentApi.cId = self.replayTheSeletedCellModel.commentId;
    }
    
    [self commitCommentRequest];
}

#pragma mark - ChatKeyBoardDataSource 这里面的评论只允许文字
- (NSArray<MoreItem *> *)chatKeyBoardMorePanelItems
{
    return nil;
}

- (NSArray<ChatToolBarItem *> *)chatKeyBoardToolbarItems
{
    return nil;
}

- (NSArray<FaceThemeModel *> *)chatKeyBoardFacePanelSubjectItems
{
    return nil;
}

#pragma mark -Empty
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView {
    return YES;
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView {
    return YES;
}

- (void)emptyDataSetDidTapView:(UIScrollView *)scrollView {
    [self requestData];
}

- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView {
    IGEmptyView *emptyView = [[IGEmptyView alloc] init];
    emptyView.title = NSLocalizedString(@"No Data", nil);
    emptyView.requestApi = self.requestApi;
    return emptyView;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    if (self.isShowKeyBoard) {
        [self.view endEditing:YES];
    }
}

//同步话题详情页与上级页面的点赞数/评论数等
- (void)topicListRefresh:(NSNotification *)notification {
    id selfClass = notification.object;
    if ([selfClass isEqualToString:NSStringFromClass([self class])]) {
        return;
    }
    [self requestData];
}

- (void)requestData {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    [[SDImageCache sharedImageCache] clearMemory];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
